package com.algorithms.utils;

@SuppressWarnings("unchecked")
public class Utils {
	public static <T> T[] genRandomLongs(int numOfArray, int maxValue, Class<T> type){
		T[] randomArr = (T[]) new Object[numOfArray];
		for (int i = 0; i < numOfArray; i++){
			randomArr[i] = type.cast((int)Math.floor((Math.random() * maxValue)));
		}
		return randomArr;
	}
	
	public static int[] genRandomInts(int numOfElements, int maxValue){
		int[] randArr = new int[numOfElements];
		for (int i = 0; i < numOfElements; i++){
			randArr[i] = (int)Math.floor((Math.random() * maxValue));
		}
		return randArr;
	}
	
	public static int getSmallestPrime(int num){
		int testNum = num;
		while (true){
			if (isPrime(testNum)){
				return testNum;
			}
			testNum++;
		}
	}
	
	/**
	 * check if the number is prime or not
	 * 
	 * @param num
	 * @return
	 */
	private static boolean isPrime(int num){
		for (int i = 2; i * i <= num; i++){
			if (num % i == 0){
				return false;
			}
		}
		return true;
	}
}
